package com.seeyon.v3x.rota.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seeyon.ctp.common.dao.BaseHibernateDao;
import com.seeyon.ctp.util.SQLWildcardUtil;
import com.seeyon.v3x.rota.dao.IRotaDao;
import com.seeyon.v3x.rota.domain.TResourceDuty;

public class RotaDaoImpl extends BaseHibernateDao  implements IRotaDao {

	public List findByLikeProperty(String likeName,String value) {
	         List objList = new ArrayList();
	         //Map parameterMap = new HashMap();
	         String hsql = "from TResourceDuty as t_resource_duty where t_resource_duty." + likeName + " like ?";
	         System.out.println(hsql);
	         Object values[] = {
	        		 (new StringBuilder()).append(SQLWildcardUtil.escape(value)).append("%").toString()
	        		 //(new StringBuilder()).append(SQLWildcardUtil.escape(value)).toString()
	         };

	         //parameterMap.put("id", Long.valueOf(id));
	         //List parameter = new ArrayList();
	         //parameter.add(Long.valueOf(id));
	         //testList = this.find(hql, -1,-1,parameterMap, new Object[0]);
	         objList = this.findVarargs(hsql, values);
	         if(objList != null) {
	        	 System.out.println("---------5555555555----------"+ "  " + objList.size()); 
	         }
	         return objList;
	}
	
	public int addTask(TResourceDuty trd) {
		this.save(trd);
		int id = trd.getId().intValue();
		System.out.println("---------idididididididididid----------"+ "  " + id); 
		return id;
	}
	
	public void updateTask(TResourceDuty trd) {
		this.update(trd);
	}
	
	public TResourceDuty findTaskById(Integer id) {
         Map parameterMap = new HashMap();
         String hql = "from TResourceDuty as t_resource_duty where t_resource_duty.id = :id";
         parameterMap.put("id", id);
         System.out.println("---------wwwwwwwwwwwwwwwwww----------"); 
         //List parameter = new ArrayList();
         //parameter.add(Long.valueOf(id));
         List<TResourceDuty> list = this.find(hql, -1,-1,parameterMap, new Object[0]);
         if(list != null) {
        	 System.out.println("---------findfindfindfindfindfind----------"+ "  " + list.size()); 
         }
         return list.get(0);
	}

}
